package snafu.framework.worlds;

import java.util.ArrayList;
import java.util.List;

import snafu.framework.objects.WorldObject;

public class Tile {
	// TODO speichern der Position wirklich nötig?
	private Position position;
	private List<WorldObject> worldObjects;

	public Tile(Position position) {
		this.position = position;
		worldObjects = new ArrayList<WorldObject>();
	}

	public Position getPosition() {
		return position;
	}
	
	public void addObject(WorldObject object) {
		worldObjects.add(object);
	}

	public void removeObject(WorldObject object) {
		worldObjects.remove(object);
	}
	
	public boolean containsObject(WorldObject object) {
		return worldObjects.contains(object);
	}

	public WorldObject getObject(Class<?> clazz) {
		for (WorldObject object : getWorldObjects()) {
			if (clazz.isAssignableFrom(object.getClass())) {
				return object;
			}
		}
		
		// not found
		return null;
	}
	
	public List<WorldObject> getWorldObjects() {
		return worldObjects;
	}
	
	@Override
	public String toString() {
		return worldObjects.size() == 0 ? "_" : worldObjects.size() + "";
	}
}
